package com.cskaoyan.market.controller.admin;

import com.cskaoyan.market.service.admin.MarketDashboardService;
import com.cskaoyan.market.vo.admin.ResponseVo;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @MethodName AdminDashboardController
 * @Description 实现显示实时的用户数量，商品数量，货品数量，订单数量
 * @Author M
 * @Date 9:17 2023/5/6
 **/
@RequiresAuthentication
@RestController
@RequestMapping("admin")
public class AdminDashboardController{

    @Autowired
    MarketDashboardService adminDashboardService;

    @GetMapping("dashboard")
    public ResponseVo dashboard(){
        Map<String, Object> result = new HashMap<>();

        int goodsTotal = adminDashboardService.getGoodsTotal();
        int userTotal = adminDashboardService.getUserTotal();
        int productTotal = adminDashboardService.getProductTotal();
        int orderTotal = adminDashboardService.getOrderTotal();

        result.put("goodsTotal",goodsTotal);
        result.put("userTotal",userTotal);
        result.put("productTotal",productTotal);
        result.put("orderTotal",orderTotal);

        ResponseVo responseVo = new ResponseVo();
        responseVo.setErrno(0);
        responseVo.setData(result);
        responseVo.setErrmsg("成功");

        return responseVo;
    }
}
